//单向channel
package main

import "fmt"

func Recv(ch<-chan int, lock chan<-bool)  {
    for value := range ch {
        fmt.Println(value)
    }
    lock<-true
}

func Send(ch chan<- int) {
    for i:=0;i<5;i++ {
        ch<-i
    }
    close(ch)
}

func main() {
    ch := make(chan int) // 双向Channel可转换为单向channel
    lock := make(chan bool)
    go Recv(ch, lock) // 只能从ch接收的Goroutine
    go Send(ch)       // 只能想ch发送的Goroutine
    <-lock
}
